<?php

// 获得运行根路径
function getAppRoot()
{
    // $_SERVER["PHP_SELF"]          -> /SteelES/index.php/Login , /SteelES/index.php/User/manageUser
    // dirname($_SERVER["PHP_SELF"]) -> /SteelES/index.php
    $result_ary = explode("/", str_replace("\\", "/", dirname($_SERVER["PHP_SELF"])));
    $result_str = "";
    foreach ($result_ary as $key => $val)
    {
        $ext_name = strtolower(substr($val, strlen($val) - 4, 4));
        if (strlen($val) > 0 && $ext_name != ".php")
            $result_str = $result_str . "/" . $val;
        if ($ext_name == ".php")
            break;
    }
    if (strlen($result_str) == 0)
        $result_str = "/";
    return $result_str;
}

// 检测PHP环境
if (version_compare(PHP_VERSION, "5.3.0", "<"))
    die("require PHP > 5.3.0 !");

// 定义自定义常量
// define("SITE_TITLE", "");
// define("APP_DISPNAME", "");
define("SALT_STR", "SES86717");
define("COOKIE_EXPIRES_MAX", "622080000");                           // cookie过期时间
define("APP_ROOT", getAppRoot());                                    // 运行根路径   /SteelES_R  （与入口文件路径一致）
$segment = (APP_ROOT == "/") ? "" : "/";
define("DEF_MODULE", $segment . "MkGc");                             // 缺省模块路径 /SteelES
define("TMPL_PATH_R", APP_ROOT . $segment . "NW_AR/Template/");      // 定义模板绝对路径 , /SteelES_R/SteelES_AR/Template/

// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
$flag_file = "./Data/ProjectDebug.dat";
define("APP_DEBUG", file_exists($flag_file) ? True : False);
define("APP_DEBUG_FLAG", file_exists($flag_file) ? True : False);

// 删除临时压缩包标记
define("APP_DELTEMPPACK_FLAG", file_exists("../Data/ProjectDebug_DelTempPack_Nw.dat") ? True : False);

// 数据库配置
$db_host_cu        = "127.0.0.1";
$db_host_file_name = "../Data/db_host_nw.txt";
if (file_exists($db_host_file_name))
{
    $db_host_cu = "192.168.168.231";
    $file_arr   = file($db_host_file_name);
    $db_host_cu = count($file_arr) > 0 ? $file_arr[0] : $db_host_cu;
    $db_host_cu = substr($db_host_cu, 0, strlen($db_host_cu) - 2);   //去除回车换行符
}
define("DB_MGE_HOST", $db_host_cu);
define("DB_MGE_TYPE", "mysql");
define("DB_MGE_PORT", "3306");
define("DB_MGE_USER", "root");
define("DB_MGE_PWD", "root");
define("DB_MGE_NAME", "nwdb");
define("DB_MGE_PREFIX", "nw_");

// 定义模板目录
define("TMPL_PATH", "./NW_AR/Template/");

// 定义应用目录
define("APP_PATH", "./NW_AR/");

// 引入ThinkPHP入口文件
require "../FrameWork/ThinkPHP_3.2.3/ThinkPHP.php";

?>